//
//  MyProfitController.m
//  PosApp
//
//  Created by 刘萍 on 2018/9/14.
//  Copyright © 2018年 李英新. All rights reserved.
//

#import "MyProfitController.h"
#import "MyProfitModel.h"
#import "LCPieView.h"
#import "LCArcView.h"
#import "LCPieViewModel.h"
#import "UIView+LCLayout.h"

#import "ProfitNewsController.h"

@interface MyProfitController ()
@property (weak, nonatomic) IBOutlet UIView *ProfitBackView;
@property (weak, nonatomic) IBOutlet UILabel *ProfitLabel;
@property (weak, nonatomic) IBOutlet UILabel *AllPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel01;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel02;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel03;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel04;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel05;
@property (weak, nonatomic) IBOutlet UILabel *PriceLabel06;

@property (strong, nonatomic) LCPieView *pieView;
@property (strong, nonatomic) NSMutableArray * DataArr;
@property (strong, nonatomic) MyProfitModel * model;
@property (strong, nonatomic) MBProgressHUD * hud;


@end

@implementation MyProfitController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.navigationItem.title = @"收益明细";

    self.ProfitLabel.layer.cornerRadius = self.ProfitLabel.bounds.size.height/2;
    self.ProfitLabel.layer.masksToBounds = YES;
    self.ProfitBackView.layer.cornerRadius = self.ProfitBackView.bounds.size.height/2;
    self.ProfitBackView.layer.masksToBounds = YES;
    
    self.pieView = [[LCPieView alloc] initWithFrame:CGRectMake(0, 0, 160, 160)];
    self.pieView.backgroundColor = KRGBColor(243, 243, 243);
    [self.ProfitBackView addSubview:self.pieView];
    [self UpLoadDataOfMyProfitController];
    
}

- (void)UpLoadDataOfMyProfitController{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];
    [dic setObject:KUseriPhone forKey:@"phone"];
    self.hud = [MainObjectWay CreateHUDView:self.view];
    [MainObjectWay PostWithMethod:@"index" andAction:@"Income" andAddParam:YES parameters:dic success:^(id responseObject) {
        NSLog(@"请求的数据 = %@",responseObject);
        if ([MainObjectWay IsSucceedWithCode:responseObject[@"code"]]) {
            NSMutableDictionary * dic = responseObject[@"data"];
            MyProfitModel * model = [MyProfitModel mj_objectWithKeyValues:dic];
            self.model = model;
            [self CreateTheController];
        }else{
            [MBProgressHUD showAlertViewWithText:responseObject[@"msg"]];
        }
        [self.hud hideAnimated:YES];
    } failure:^(NSError *error) {
        [self.hud hideAnimated:YES];
        NSLog(@"错误信息 = %@",error);
    }];
}

- (void)CreateTheController{
    [self.DataArr removeAllObjects];
    self.AllPriceLabel.text = [NSString stringWithFormat:@"%@",self.model.member_list_income];
    self.PriceLabel01.text = [NSString stringWithFormat:@"%@元",self.model.pos_income];
    self.PriceLabel02.text = [NSString stringWithFormat:@"%@元",self.model.points_income];
    self.PriceLabel03.text = [NSString stringWithFormat:@"%@元",self.model.card_income];
    self.PriceLabel04.text = [NSString stringWithFormat:@"%@元",self.model.refund_income];
    self.PriceLabel05.text = [NSString stringWithFormat:@"%@元",self.model.up_income];
    self.PriceLabel06.text = [NSString stringWithFormat:@"%@元",self.model.draw_income];
    
    
    NSString * str01 = [NSString stringWithFormat:@"%.2f",[self.model.pos_income floatValue]/[self.model.member_list_income floatValue]];
    LCPieViewModel *modelP1 = [LCPieViewModel modelWithValue:[str01 floatValue] color:KRGBColor(229, 109, 67) text:@""];
    
    NSString * str02 = [NSString stringWithFormat:@"%.2f",[self.model.points_income floatValue]/[self.model.member_list_income floatValue]];
    LCPieViewModel *modelP2 = [LCPieViewModel modelWithValue:[str02 floatValue] color:KRGBColor(85, 167, 229) text:@""];
    
    NSString * str03 = [NSString stringWithFormat:@"%.2f",[self.model.card_income floatValue]/[self.model.member_list_income floatValue]];
    LCPieViewModel *modelP3 = [LCPieViewModel modelWithValue:[str03 floatValue] color:KRGBColor(231, 166, 71) text:@""];
    
    NSString * str04 = [NSString stringWithFormat:@"%.2f",[self.model.refund_income floatValue]/[self.model.member_list_income floatValue]];
    LCPieViewModel *modelP4 = [LCPieViewModel modelWithValue:[str04 floatValue] color:KRGBColor(146, 91, 235) text:@""];
    
    NSString * str05 = [NSString stringWithFormat:@"%.2f",([self.model.up_income floatValue]+[self.model.doctor_income floatValue]+[self.model.draw_income floatValue])/[self.model.member_list_income floatValue]];
    LCPieViewModel *modelP5 = [LCPieViewModel modelWithValue:[str05 floatValue] color:KRGBColor(98, 197, 143) text:@""];
    
    NSString * str06 = [NSString stringWithFormat:@"%.2f",([self.model.up_income floatValue]+[self.model.doctor_income floatValue]+[self.model.draw_income floatValue])/[self.model.member_list_income floatValue]];
    LCPieViewModel *modelP6 = [LCPieViewModel modelWithValue:[str06 floatValue] color:KRGBColor(112, 211, 93) text:@""];
    
    self.pieView.showText = NO;
    self.pieView.showPercent = YES;
    self.pieView.isCanClick = YES;
    [self.pieView showPieViewWithDataSource:@[modelP1, modelP2, modelP3, modelP4, modelP5, modelP6]];
}

- (void)ClickOnBtnOfRightBtn{
    [MBProgressHUD showAlertViewWithText:@"收支明细界面"];
}
- (IBAction)ClickOnBtnOfBtn01:(id)sender {
    ProfitNewsController * NewsC = [[ProfitNewsController alloc] init];
    NewsC.NewsType = @"2";
    [self.navigationController pushViewController:NewsC animated:YES];
}
- (IBAction)ClickOnBtnOfBtn02:(id)sender {
    ProfitNewsController * NewsC = [[ProfitNewsController alloc] init];
    NewsC.NewsType = @"4";
    [self.navigationController pushViewController:NewsC animated:YES];
}
- (IBAction)ClickOnBtnOfBtn03:(id)sender {
    ProfitNewsController * NewsC = [[ProfitNewsController alloc] init];
    NewsC.NewsType = @"3";
    [self.navigationController pushViewController:NewsC animated:YES];
}
- (IBAction)ClickOnBtnOfBtn04:(id)sender {
    ProfitNewsController * NewsC = [[ProfitNewsController alloc] init];
    NewsC.NewsType = @"5";
    [self.navigationController pushViewController:NewsC animated:YES];
}
- (IBAction)ClickOnBtnOfBtn05:(id)sender {
    ProfitNewsController * NewsC = [[ProfitNewsController alloc] init];
    NewsC.NewsType = @"1";
    [self.navigationController pushViewController:NewsC animated:YES];
}
- (IBAction)ClickOnBtnOfBtn06:(id)sender {
    ProfitNewsController * NewsC = [[ProfitNewsController alloc] init];
    NewsC.NewsType = @"6";
    [self.navigationController pushViewController:NewsC animated:YES];
}

- (NSMutableArray *)DataArr {
    if (!_DataArr) {
        _DataArr = [NSMutableArray array];
    }
    return _DataArr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
